import React, { Component } from 'react'
import qs from 'querystring'


// 多组符号用&号连接的叫“urlencoded”编码
// key=value&key=value&key=value

let obj = {name: 'tom', age:18} 
console.log(qs.stringify(obj)); // name=tom&age=18

let str = 'carName=奔驰&price=199'
console.log(qs.parse(str)); // {carName: "奔驰", price: "199"}

const DetailData = [
  {id: 1, content: '你好，这是消息1的内容'},
  {id: 2, content: '你好，这是消息2的内容'},
  {id: 3, content: '你好，这是消息3的内容'},  
]

export default class Detail extends Component {
  render() {
    console.log(this.props);
    // 接收params参数
    // const {id, title} = this.props.match.params;

    // 接收search参数
    // const {search} = this.props.location;
    // const {id, title} = qs.parse(search.slice(1));

    // 接收state参数
    const {id, title} = this.props.location.state || {};

    const findResult = DetailData.find(item => item.id == id) || {};
    return (
      <div>
        <ul>
          <li>ID:{id}</li>
          <li>TITLE:{title}</li>
          <li>CONTENT:{findResult.content}</li>
        </ul>
      </div>
    )
  }
}
